﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel.Security;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyUAMS.BLL;

public partial class Login : System.Web.UI.Page
{
    
    CustomerService CustomerSrv= new CustomerService();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["name"]!=null)
            {
                txtName.Text = Request.QueryString["name"];
                status_label.Text = "注册成功，请登录！";
            }
        }
    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        if(Page.IsValid)
        {
            int customerId=CustomerSrv.CheckLogin(txtName.Text.Trim(),txtPwd.Text.Trim());
            if (customerId > 0)
            {
                Session.Clear();
                if(txtName.Text.Trim() == "admin")
                {
                    Session["AminId"] = customerId;
                    Session["AdminName"]=txtName.Text;
                    Response.Redirect("~/Admin/AdminWork.aspx");
                }
                else
                {
                    Session["CustomerId"] = customerId;
                    Session["CustomerName"]=txtName.Text;
                    Response.Redirect("~/UserWork/MyWork.aspx");
                }
            }
        }
    }
}